package com.example.block_chain.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;

/*
 *@description: 路径生成器
 *@author: hisen
 *@Time: 2023/10/27  0:19
 */
public class PathUtil {

    public static String generateFileDir(String schoolCode) {
        // 根据日期生成路径 schoolCode/2023/10/27/00
        SimpleDateFormat sdf = new SimpleDateFormat("/yyyy/MM/dd/HH/");
        return schoolCode + sdf.format(new Date());
    }
    public static String generateFilePath(String schoolCode,String fileName) {
        //根据日期生成路径   schoolCode/2023/11/15/
        SimpleDateFormat sdf = new SimpleDateFormat("/yyyy/MM/dd/");
        String datePath = schoolCode+sdf.format(new Date());
        //uuid作为文件名
        String uuid = UUID.randomUUID().toString().replaceAll("-", "");
        //后缀和文件后缀一致
        int index = fileName.lastIndexOf(".");
        // test.jpg -> .jpg
        String fileType = fileName.substring(index);
        return "/" + datePath + uuid + fileType;
    }
}